Skip to content

Commit 1365233

Browse files
authored
- Further expanding playwright coverage over the KB article editing (over both Edit Article & Edit Article Metadata areas). (#5964)
- Reducing the complexity of some KB article steps.
1 parent 46481d6 commit 1365233

18 files changed

+1093
-291
lines changed

playwright_tests/flows/explore_articles_flows/article_flows/add_kb_article_flow.py

Lines changed: 130 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
AddKbMediaFlow
66
from playwright_tests.messages.explore_help_articles.kb_article_page_messages import (
77
KBArticlePageMessages)
8+
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage
9+
from playwright_tests.pages.explore_help_articles.articles.kb_article_review_revision_page import \
10+
KBArticleReviewRevisionPage
11+
from playwright_tests.pages.explore_help_articles.articles.kb_article_show_history_page import \
12+
KBArticleShowHistoryPage
13+
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_page import \
14+
EditKBArticlePage
815
from playwright_tests.pages.explore_help_articles.articles.submit_kb_article_page import (
916
SubmitKBArticlePage)
1017

1118

12-
class AddKbArticleFlow(TestUtilities, SubmitKBArticlePage, AddKbMediaFlow):
19+
class AddKbArticleFlow(TestUtilities, SubmitKBArticlePage, AddKbMediaFlow, KBArticlePage,
20+
KBArticleShowHistoryPage, KBArticleReviewRevisionPage, EditKBArticlePage):
1321

1422
def __init__(self, page: Page):
1523
super().__init__(page)
@@ -29,7 +37,8 @@ def submit_simple_kb_article(self,
2937
is_template=False,
3038
expiry_date=None,
3139
restricted_to_groups: list[str] = None,
32-
single_group=""
40+
single_group="",
41+
approve_first_revision=False
3342
) -> dict[str, Any]:
3443
self._page.goto(KBArticlePageMessages.CREATE_NEW_KB_ARTICLE_STAGE_URL)
3544

@@ -62,30 +71,38 @@ def submit_simple_kb_article(self,
6271

6372
if article_category is None:
6473
if is_template:
74+
article_category = kb_article_test_data["kb_template_category"]
6575
super()._select_category_option_by_text(
66-
kb_article_test_data["kb_template_category"]
76+
article_category
6777
)
6878
else:
69-
super()._select_category_option_by_text(kb_article_test_data["category_options"])
79+
article_category = kb_article_test_data["category_options"]
80+
super()._select_category_option_by_text(article_category)
7081
else:
7182
super()._select_category_option_by_text(article_category)
7283

7384
if not allow_translations:
7485
super()._check_allow_translations_checkbox()
7586

87+
relevancy = kb_article_test_data["relevant_to_option"]
7688
if selected_relevancy is True:
7789
super()._click_on_a_relevant_to_option_checkbox(
78-
kb_article_test_data["relevant_to_option"]
90+
relevancy
7991
)
8092

93+
article_topic = [
94+
kb_article_test_data["selected_parent_topic"],
95+
kb_article_test_data["selected_child_topic"]
96+
]
97+
8198
# Adding Article topic
8299
if selected_topics is True:
83100
super()._click_on_a_particular_parent_topic(
84-
kb_article_test_data["selected_parent_topic"]
101+
article_topic[0]
85102
)
86103
super()._click_on_a_particular_child_topic_checkbox(
87-
kb_article_test_data["selected_parent_topic"],
88-
kb_article_test_data["selected_child_topic"],
104+
article_topic[0],
105+
article_topic[1],
89106
)
90107

91108
# Interacting with Allow Discussion checkbox
@@ -127,6 +144,7 @@ def submit_simple_kb_article(self,
127144
'document.getElementById("id_slug").value'
128145
)
129146

147+
first_revision_id = None
130148
if submit_article is True:
131149
# If title and slug are empty we are not reaching the description field.
132150
if ((article_title != '') and (article_slug != '') and (
@@ -136,19 +154,122 @@ def submit_simple_kb_article(self,
136154
kb_article_test_data["changes_description"]
137155
)
138156
super()._click_on_changes_submit_button()
157+
try:
158+
first_revision_id = super()._get_last_revision_id()
159+
except IndexError:
160+
print("Chances are that the form was not submitted successfully")
139161
else:
140162
super()._click_on_submit_for_review_button()
141163

142164
article_url = super()._get_article_page_url()
143165

166+
if approve_first_revision:
167+
super()._click_on_show_history_option()
168+
self.approve_kb_revision(first_revision_id)
169+
144170
return {"article_title": kb_article_title,
145171
"article_content": kb_article_test_data["article_content"],
146172
"article_content_html": kb_article_test_data['article_content_html_rendered'],
147173
"article_slug": slug,
148174
"article_child_topic": kb_article_test_data["selected_child_topic"],
175+
"article_category": article_category,
176+
"article_relevancy": relevancy,
177+
"article_topic": article_topic,
149178
"article_review_description": kb_article_test_data["changes_description"],
150179
"keyword": kb_article_test_data["keywords"],
151180
"search_results_summary": kb_article_test_data["search_result_summary"],
152181
"expiry_date": kb_article_test_data["expiry_date"],
153-
"article_url": article_url
182+
"article_url": article_url,
183+
"first_revision_id": first_revision_id
184+
}
185+
186+
def approve_kb_revision(self, revision_id: str,
187+
revision_needs_change=False,
188+
ready_for_l10n=False):
189+
if (KBArticlePageMessages.KB_ARTICLE_HISTORY_URL_ENDPOINT not in
190+
super()._get_current_page_url()):
191+
super()._click_on_show_history_option()
192+
193+
super()._click_on_review_revision(
194+
revision_id
195+
)
196+
super()._click_on_approve_revision_button()
197+
198+
if revision_needs_change:
199+
if not super()._is_needs_change_checkbox_checked():
200+
super()._click_on_needs_change_checkbox()
201+
super()._add_text_to_needs_change_comment(
202+
super().kb_revision_test_data['needs_change_message']
203+
)
204+
205+
if ready_for_l10n:
206+
super()._check_ready_for_localization_checkbox()
207+
208+
super()._click_accept_revision_accept_button()
209+
210+
def submit_new_kb_revision(self,
211+
keywords=None,
212+
search_result_summary=None,
213+
content=None,
214+
expiry_date=None,
215+
changes_description=None,
216+
is_admin=False,
217+
approve_revision=False
218+
) -> dict[str, Any]:
219+
220+
super()._click_on_edit_article_option()
221+
222+
# Only admin accounts can update article keywords.
223+
if is_admin:
224+
# Keywords step.
225+
if keywords is None:
226+
super()._fill_edit_article_keywords_field(
227+
self.kb_article_test_data['updated_keywords']
228+
)
229+
else:
230+
super()._fill_edit_article_keywords_field(keywords)
231+
232+
# Search Result Summary step.
233+
if search_result_summary is None:
234+
super()._fill_edit_article_search_result_summary_field(
235+
self.kb_article_test_data['updated_search_result_summary']
236+
)
237+
else:
238+
super()._fill_edit_article_search_result_summary_field(search_result_summary)
239+
240+
# Content step.
241+
if content is None:
242+
super()._fill_edit_article_content_field(
243+
self.kb_article_test_data['updated_article_content']
244+
)
245+
else:
246+
super()._fill_edit_article_content_field(content)
247+
248+
# Expiry date step.
249+
if expiry_date is None:
250+
super()._fill_edit_article_expiry_date(
251+
self.kb_article_test_data['updated_expiry_date']
252+
)
253+
else:
254+
super()._fill_edit_article_expiry_date(expiry_date)
255+
256+
# Submitting for preview steps
257+
super()._click_submit_for_review_button()
258+
259+
if changes_description is None:
260+
super()._fill_edit_article_changes_panel_comment(
261+
self.kb_article_test_data['changes_description']
262+
)
263+
else:
264+
super()._fill_edit_article_changes_panel_comment(changes_description)
265+
266+
super()._click_edit_article_changes_panel_submit_button()
267+
268+
revision_id = super()._get_last_revision_id()
269+
270+
if approve_revision:
271+
self.approve_kb_revision(revision_id)
272+
273+
return {"revision_id": revision_id,
274+
"changes_description": self.kb_article_test_data['changes_description']
154275
}

playwright_tests/flows/explore_articles_flows/article_flows/add_kb_revision_flow.py

Lines changed: 0 additions & 108 deletions
This file was deleted.

playwright_tests/flows/explore_articles_flows/article_flows/edit_article_meta_flow.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
from playwright_tests.core.testutilities import TestUtilities
22
from playwright.sync_api import Page
33

4+
from playwright_tests.messages.explore_help_articles.kb_article_revision_page_messages import \
5+
KBArticleRevision
6+
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage
47
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_meta import (
58
KBArticleEditMetadata)
9+
from playwright_tests.pages.explore_help_articles.articles.submit_kb_article_page import \
10+
SubmitKBArticlePage
611

712

8-
class EditArticleMetaFlow(TestUtilities, KBArticleEditMetadata):
13+
class EditArticleMetaFlow(TestUtilities, KBArticleEditMetadata, SubmitKBArticlePage,
14+
KBArticlePage):
915

1016
def __init__(self, page: Page):
1117
super().__init__(page)
1218

1319
def edit_article_metadata(self, title=None,
20+
slug=None,
21+
category=None,
22+
relevancy=None,
23+
topics=None,
24+
obsolete=False,
25+
discussions=True,
1426
needs_change=False,
1527
needs_change_comment=False,
1628
restricted_to_groups: list[str] = None,
1729
single_group=""):
1830

31+
if KBArticleRevision.KB_EDIT_METADATA not in super()._get_current_page_url():
32+
super()._click_on_edit_article_metadata()
33+
1934
if restricted_to_groups is not None:
2035
for group in restricted_to_groups:
2136
super()._add_and_select_restrict_visibility_group_metadata(group)
@@ -25,6 +40,34 @@ def edit_article_metadata(self, title=None,
2540
if title is not None:
2641
super()._add_text_to_title_field(title)
2742

43+
if slug is not None:
44+
super()._add_text_to_slug_field(slug)
45+
46+
if category is not None:
47+
super()._select_category(category)
48+
49+
if relevancy is not None:
50+
super()._check_a_particular_relevancy_option(relevancy)
51+
52+
if topics is not None:
53+
super()._click_on_a_particular_parent_topic(
54+
topics[0]
55+
)
56+
super()._click_on_a_particular_child_topic_checkbox(
57+
topics[0],
58+
topics[1],
59+
)
60+
61+
if obsolete:
62+
super()._click_on_obsolete_checkbox()
63+
64+
if discussions:
65+
if not super()._is_allow_discussion_checkbox_checked():
66+
super()._click_on_allow_discussion_on_article_checkbox()
67+
else:
68+
if super()._is_allow_discussion_checkbox_checked():
69+
super()._click_on_allow_discussion_on_article_checkbox()
70+
2871
# If it needs change we are going to ensure that the needs change checkbox is checked.
2972
if needs_change:
3073
if not super()._is_needs_change_checkbox():

playwright_tests/messages/explore_help_articles/kb_article_page_messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ class KBArticlePageMessages:
2121
KB_ARTICLE_RELEVANCY_ERROR = "Please select at least one product."
2222
KB_ARTICLE_TOPIC_ERROR = "Please select at least one topic."
2323
KB_ARTICLE_RESTRICTED_BANNER = "This document is restricted."
24+
25+
def get_template_error(self, article_title) -> str:
26+
return (f'Documents in the Template category must have titles that start with '
27+
f'"Template:". (Current title is "{article_title}")')

0 commit comments

Comments
 (0)